/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package ai.group;

import net.sf.l2j.gameserver.model.actor.L2Npc;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.network.clientpackets.Say2;
import net.sf.l2j.gameserver.network.serverpackets.NpcSay;
import ai.L2AttackableAIScript;

/**
 * Speaking NPCs implementation.<br><br>
 * This AI leads the behavior of any speaking NPC.<br>
 * It sends back the good string following the action and the npcId.
 * @author Tryskell
 */
public class SpeakingNPCs extends L2AttackableAIScript
{
	private static final int[] NPC_IDS =
	{ 
		27016, // Nerkas
		27021, // Kirunak
		27022  // Merkenis
	};
	
	public SpeakingNPCs(int questId, String name, String descr)
	{
		super(questId, name, descr);
		this.registerMobs(NPC_IDS, QuestEventType.ON_ATTACK, QuestEventType.ON_KILL);
	}
	
	@Override
	public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isPet)
	{
		if (npc.hasSpoken())
			return super.onAttack(npc,attacker,damage,isPet);
		
		int npcId = npc.getNpcId();
		String message = "";
		
		switch (npcId)
		{
			case 27016:
				message = "...How dare you challenge me!";
				break;
			
			case 27021:
				message = "I will taste your blood!";
				break;
				
			case 27022:
				message = "I shall put you in a never-ending nightmare!";
				break;
		}
		
		npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.ALL, npc.getNpcId(), message));
		npc.setHasSpoken(true); // Make the mob speaks only once, else he will spam.
		
		return super.onAttack(npc,attacker,damage,isPet);
	}
	
	@Override
	public String onKill(L2Npc npc, L2PcInstance player, boolean isPet)
	{
		int npcId = npc.getNpcId();
		String message = "";
		
		switch (npcId)
		{
			case 27016:
				message = "May Beleth's power be spread on the whole world...!";
				break;
			
			case 27021:
				message = "I have fulfilled my contract with Trader Creamees.";
				break;
				
			case 27022:
				message = "My soul belongs to Icarus...";
				break;
		}
		
		npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.ALL, npc.getNpcId(), message));
		npc.setHasSpoken(false); // Reset the flag, to unmute the NPC.
		
		return super.onKill(npc,player,isPet);
	}
	
	public static void main(String[] args)
	{
		// now call the constructor (starts up the ai)
		new SpeakingNPCs(-1, "SpeakingNPCs", "ai");
	}
}